﻿Imports AugmentLib.Database
Imports System.Configuration.ConfigurationManager
Imports AugmentLib.InputOutput.Encryption
Imports AugmentLib.WebComponent
Imports Lsk.Data
Imports Lsk.Business
Imports FlickrNet
Partial Class MobileSetting
    Inherits System.Web.UI.Page

    Protected Sub BtnSave_Click(sender As Object, e As EventArgs) Handles BtnSave.Click

        'Check if should update or save

        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Try
            objDB.OpenConnection()
            objDB.InitDbTrans()
            objDB.AddParameter("CompanyName", Data.SqlDbType.NVarChar, txtCompanyName.Text) 'lenght=10
            objDB.AddParameter("Address", Data.SqlDbType.NVarChar, txtAddress.Text) '300
            objDB.AddParameter("CompanyPhone", Data.SqlDbType.NVarChar, txtCompanyPhone.Text) '50
            objDB.AddParameter("MobilePhone", Data.SqlDbType.NVarChar, txtMobilePhone.Text) '50
            objDB.AddParameter("Email", Data.SqlDbType.NVarChar, txtEmail.Text)
            objDB.AddParameter("Website", Data.SqlDbType.NVarChar, txtWebsite.Text)
            objDB.AddParameter("Fblink", Data.SqlDbType.NVarChar, txtFblink.Text)
            objDB.AddParameter("Longitude", Data.SqlDbType.Decimal, txtLongitude.Text)
            objDB.AddParameter("Latitude", Data.SqlDbType.Decimal, txtLatitude.Text)
            objDB.AddParameter("Disclaimer", Data.SqlDbType.NVarChar, txtDisclaimer.Text)
            objDB.AddParameter("AboutUs", Data.SqlDbType.NVarChar, txtAboutUs.Text)
            objDB.AddParameter("Module0", Data.SqlDbType.NVarChar, txtModule0.Text)
            objDB.AddParameter("Module1", Data.SqlDbType.NVarChar, txtModule1.Text)
            objDB.AddParameter("Module2", Data.SqlDbType.NVarChar, txtModule2.Text)
            objDB.AddParameter("Module3", Data.SqlDbType.NVarChar, txtModule3.Text)
            objDB.AddParameter("Module4", Data.SqlDbType.NVarChar, txtModule4.Text)
            objDB.AddParameter("Module5", Data.SqlDbType.NVarChar, txtModule5.Text)
            objDB.AddParameter("Module6", Data.SqlDbType.NVarChar, txtModule6.Text)
            objDB.AddParameter("Module7", Data.SqlDbType.NVarChar, txtModule7.Text)
            objDB.AddParameter("Module8", Data.SqlDbType.NVarChar, txtModule8.Text)
            objDB.AddParameter("Module9", Data.SqlDbType.NVarChar, txtModule9.Text)
            objDB.AddParameter("Module10", Data.SqlDbType.NVarChar, txtModule10.Text)
            objDB.AddParameter("Module11", Data.SqlDbType.NVarChar, txtModule11.Text)
            objDB.AddParameter("Module12", Data.SqlDbType.NVarChar, txtModule12.Text)
            objDB.AddParameter("Module13", Data.SqlDbType.NVarChar, txtModule13.Text)
            objDB.AddParameter("Module14", Data.SqlDbType.NVarChar, txtModule14.Text)
            objDB.AddParameter("Module15", Data.SqlDbType.NVarChar, txtModule15.Text)
            objDB.AddParameter("Module16", Data.SqlDbType.NVarChar, txtModule16.Text)
            objDB.AddParameter("Module17", Data.SqlDbType.NVarChar, txtModule17.Text)
            objDB.AddParameter("Module18", Data.SqlDbType.NVarChar, txtModule18.Text)
            objDB.AddParameter("Module19", Data.SqlDbType.NVarChar, txtModule19.Text)
            objDB.AddParameter("Module20", Data.SqlDbType.NVarChar, txtModule20.Text)
            objDB.AddParameter("Module21", Data.SqlDbType.NVarChar, txtModule21.Text)
            objDB.AddParameter("Module22", Data.SqlDbType.NVarChar, txtModule22.Text)
            objDB.AddParameter("Module23", Data.SqlDbType.NVarChar, txtModule23.Text)
            objDB.AddParameter("Module24", Data.SqlDbType.NVarChar, txtModule24.Text)
            objDB.AddParameter("Culture", Data.SqlDbType.NVarChar, txtCulture.Text)
            objDB.AddParameter("Vision", Data.SqlDbType.NVarChar, txtVision.Text)
            objDB.AddParameter("Mission", Data.SqlDbType.NVarChar, txtMission.Text)
            objDB.AddParameter("Profile", Data.SqlDbType.NVarChar, txtProfile.Text)
            objDB.AddParameter("PDPA", Data.SqlDbType.NVarChar, txtPdpa.Text)
            'objDB.AddParameter("UpdateWho", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidStaffId.Text))

            objDB.dbVariable.SQLString = "UPDATE Mobile_Settings SET Address=@Address," &
                "CompanyPhone=@CompanyPhone,MobilePhone=@MobilePhone,Email=@Email,Website=@Website,Fblink=@Fblink," &
                "Longitude=@Longitude,Latitude=@Latitude,Disclaimer=@Disclaimer,AboutUs=@AboutUs,Module0=@Module0,Module1=@Module1,Module2=@Module2,Module3=@Module3,Module4=@Module4," &
                "Module5=@Module5,Module6=@Module6,Module7=@Module7,Module8=@Module8,Module9=@Module9,Module10=@Module10,Module11=@Module11,Module12=@Module12,Module13=@Module13,Module14=@Module14," &
                "Module15=@Module15,Module16=@Module16,Module17=@Module17,Module18=@Module18,Module19=@Module19,Module20=@Module20,Module21=@Module21,Module22=@Module22,Module23=@Module23,Module24=@Module24," &
                "Culture=@Culture,Vision=@Vision,Mission=@Mission,Profile=@Profile,PDPA=@PDPA," &
                "CreateDate=getdate() where CompanyName=@CompanyName"


            objDB.ExecuteQuery(False)
            objDB.DbTransCommit()

            objDB.CloseConnection()

            'Success, alert success. Clear Textbox

            lblMsgSuccessful.Text = txtCompanyName.Text + " updated successfully."


            divSuccessful.Visible = True
            udpMessage.Update()
            upPropertyDetail.Update()

        Catch ex As NullReferenceException
            If objDB.dbVariable.objConn.State = Data.ConnectionState.Open Then
                objDB.DbTransRollback()
                objDB.CloseConnection()
            End If
            lblMsgError.Text = ex.Message
            divError.Visible = True
            udpMessage.Update()

        End Try
    End Sub

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        If Session("StaffId") Is Nothing Then
            Response.Redirect("Default.aspx")
        Else
            lblhidStaffId.Text = Session("StaffId").ToString
            lblhidStaffType.Text = Session("StaffType").ToString
        End If

        If (lblhidStaffType.Text = "4" Or lblhidStaffType.Text = "6" Or lblhidStaffType.Text = "2" Or lblhidStaffType.Text = "5") Then
            Response.Redirect("Dashboard.aspx")
        End If

        If Not Page.IsPostBack Then
            LoadSettings()
        Else

        End If

    End Sub

    Protected Function LoadSettings() As Integer

        'Return 1 if the AuctionID exist, 0 if the property never exist.
        Dim retval = 0

        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable
        Try
            objDB.OpenConnection()

            objDB.dbVariable.SQLString = "SELECT [CompanyName],[Address],[CompanyPhone]" &
          ",[MobilePhone],[Email],[Website],[Fblink],[Longitude],[Latitude],[Disclaimer],[AboutUs],[Module0],[Module1],[Module2]" &
          ",[Module3],[Module4],[Module5],[Module6],[Module7],[Module8],[Module9],[Module10],[Module11],[Module12],[Module13]" &
          ",[Module14],[Module15],[Module16],[Module17],[Module18],[Module19],[Module20],[Module21],[Module22],[Module23],[Module24],[CreateDate],[StatusDelete]" &
          ",[Culture],[Vision],[Mission],[Profile],[PDPA] " &
          " FROM [dbo].[Mobile_Settings]"

            objDB.FillData(TempDT, "MobileSettings", Database.SQLCommandType.NormalString)
            objDB.CloseConnection()

            For Each ReadRow As Data.DataRow In TempDT.Rows


                txtCompanyName.Text = ReadRow.Item("CompanyName").ToString
                txtAddress.Text = ReadRow.Item("Address").ToString
                txtCompanyPhone.Text = ReadRow.Item("CompanyPhone").ToString
                txtMobilePhone.Text = ReadRow.Item("MobilePhone").ToString
                txtEmail.Text = ReadRow.Item("Email").ToString
                txtWebsite.Text = ReadRow.Item("Website").ToString
                txtFblink.Text = ReadRow.Item("Fblink").ToString
                txtLongitude.Text = ReadRow.Item("Longitude").ToString
                txtLatitude.Text = ReadRow.Item("Latitude").ToString
                txtDisclaimer.Text = ReadRow.Item("Disclaimer").ToString
                txtAboutUs.Text = ReadRow.Item("AboutUs").ToString
                txtModule0.Text = ReadRow.Item("Module0").ToString
                txtModule1.Text = ReadRow.Item("Module1").ToString
                txtModule2.Text = ReadRow.Item("Module2").ToString
                txtModule3.Text = ReadRow.Item("Module3").ToString
                txtModule4.Text = ReadRow.Item("Module4").ToString
                txtModule5.Text = ReadRow.Item("Module5").ToString
                txtModule6.Text = ReadRow.Item("Module6").ToString
                txtModule7.Text = ReadRow.Item("Module7").ToString
                txtModule8.Text = ReadRow.Item("Module8").ToString
                txtModule9.Text = ReadRow.Item("Module9").ToString
                txtModule10.Text = ReadRow.Item("Module10").ToString
                txtModule11.Text = ReadRow.Item("Module11").ToString
                txtModule12.Text = ReadRow.Item("Module12").ToString
                txtModule13.Text = ReadRow.Item("Module13").ToString
                txtModule14.Text = ReadRow.Item("Module14").ToString
                txtModule15.Text = ReadRow.Item("Module15").ToString
                txtModule16.Text = ReadRow.Item("Module16").ToString
                txtModule17.Text = ReadRow.Item("Module17").ToString
                txtModule18.Text = ReadRow.Item("Module18").ToString
                txtModule19.Text = ReadRow.Item("Module19").ToString
                txtModule20.Text = ReadRow.Item("Module20").ToString
                txtModule21.Text = ReadRow.Item("Module21").ToString
                txtModule22.Text = ReadRow.Item("Module22").ToString
                txtModule23.Text = ReadRow.Item("Module23").ToString
                txtModule24.Text = ReadRow.Item("Module24").ToString
                txtCulture.Text = ReadRow.Item("Culture").ToString
                txtVision.Text = ReadRow.Item("Vision").ToString
                txtMission.Text = ReadRow.Item("Mission").ToString
                txtProfile.Text = ReadRow.Item("Profile").ToString
                txtPdpa.Text = ReadRow.Item("PDPA").ToString
            Next
        Catch ex As Exception
            lblMsgError.Text = ex.Message
            divError.Visible = True
            udpMessage.Update()
        End Try

        Return retval
    End Function


    Private Function getName(ByVal StaffId As String) As String
        Dim StaffName As String = String.Empty
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()

        'objDB.dbVariable.SQLString = "Select Name FROM AW_Staff WHERE StaffId = @StaffId AND StatusDelete = 0"
        objDB.dbVariable.SQLString = "Select Name FROM AW_Staff WHERE StaffId = @StaffId"
        objDB.AddParameter("StaffId", Data.SqlDbType.UniqueIdentifier, New Guid(StaffId))

        objDB.FillData(TempDT, "AW_Staff", Database.SQLCommandType.NormalString)

        objDB.CloseConnection()

        If TempDT.Rows.Count > 0 Then
            StaffName = TempDT.Rows(0).Item("Name").ToString
        End If

        Return StaffName
    End Function

    Protected Sub btnBack_Click(sender As Object, e As EventArgs) Handles btnBack.Click
        Response.Redirect("Dashboard.aspx")
    End Sub
End Class
